class Solution:
    def maxSumTwoNoOverlap(self, A: list, L: int, M: int) -> int:
        for i in range(1, len(A)):
            A[i] += A[i - 1]
        res = A[L + M - 1]
        max_l = A[L - 1]
        max_m = A[M - 1]
        for i in range(L + M, len(A)):
            max_l = max(max_l, A[i - M] - A[i - M - L])
            max_m = max(max_m, A[i - L] - A[i - M - L])
            res = max(res, max_l + A[i] - A[i - M], max_m + A[i] - A[i - L])

        return res
